# -*- coding:utf-8 -*-
from pydantic import Field, BaseModel
from typing import Union
from sqlalchemy import Column, Integer, String, DateTime, Enum, DECIMAL, Float, TEXT
from core.curd import Base, TimestampMixin


class SysDictType(Base, TimestampMixin):
    """
    数据字典表
    """
    __tablename__ = 'sys_dict_type'

    id = Column(Integer, nullable=False, autoincrement=True, primary_key=True, comment='id')
    dict_type = Column(String(100), nullable=False, comment='字典类型')
    dict_name = Column(String(255), nullable=False, comment='字典名称')
    dict_source = Column(Integer, comment='来源  0：字典数据  1：动态SQL')
    dict_sql = Column(String(500), comment='动态SQL')
    sort = Column(Integer, comment='排序')
    tenant_id = Column(Integer, comment='租户ID')
    version = Column(Integer, comment='版本号')
    deleted = Column(Integer, comment='删除标识  0：正常   1：已删除')
    creator = Column(Integer, comment='创建者')
    updater = Column(Integer, comment='更新者')


class SysDictData(Base, TimestampMixin):
    """
    数据字典表
    """
    __tablename__ = 'sys_dict_data'

    id = Column(Integer, nullable=False, autoincrement=True, primary_key=True, comment='id')
    dict_type_id = Column(Integer, nullable=False, comment='字典类型ID')
    dict_label = Column(String(255), nullable=False, comment='字典标签')
    dict_value = Column(String(255), comment='字典值')
    label_class = Column(String(100), comment='标签样式')
    sort = Column(Integer, comment='排序')
    tenant_id = Column(Integer, comment='租户ID')
    version = Column(Integer, comment='版本号')
    deleted = Column(Integer, comment='删除标识  0：正常   1：已删除')
    creator = Column(Integer, comment='创建者')
    updater = Column(Integer, comment='更新者')


class CreateSysDictType(BaseModel):
    dict_type: str = Field(comment='字典类型', max_length=50)
    dict_name: str = Field(comment='字典名称', max_length=100)
    dict_source: int = Field(comment='数据来源 0 数据字典 1 动态SQL')
    dict_sql: Union[str,None] = Field(comment='SQL')
    sort: int = Field(comment='排序权重')
    remark: str = Field(comment='备注', max_length=500)


class UpdateSysDictType(BaseModel):
    id: int = Field(comment='id')
    dict_type: str = Field(comment='字典类型', max_length=50)
    dict_name: str = Field(comment='字典名称', max_length=100)
    dict_source: int = Field(comment='数据来源 0 数据字典 1 动态SQL')
    dict_sql: Union[str,None] = Field(comment='SQL')
    sort: int = Field(comment='排序权重')
    remark: str = Field(comment='备注', max_length=500)


class CreateSysDictData(BaseModel):
    dict_type_id: int = Field(comment='字典类型ID')
    dict_label: str = Field(comment='字典标签', max_length=50)
    dict_value: str = Field(comment='字典值', max_length=100)
    label_class: str = Field(comment='字典样式')
    sort: int = Field(comment='排序权重')
    remark: str = Field(comment='备注', max_length=500)
    

class UpdateSysDictData(BaseModel):
    id: int = Field(comment='id')
    dict_type_id: int = Field(comment='字典类型ID')
    dict_label: str = Field(comment='字典标签', max_length=50)
    dict_value: str = Field(comment='字典值', max_length=100)
    label_class: str = Field(comment='字典样式')
    sort: int = Field(comment='排序权重')
    remark: str = Field(comment='备注', max_length=500)
